package com.ysu.shop.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.ysu.shop.pojo.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 霍京
 * @since 2021-3-03
 */
public interface UserMapper extends BaseMapper<User> {
    @Select("select username,phone,email,question from user ${ew.customSqlSegment}")
    User getUserById(@Param(Constants.WRAPPER) Wrapper wrapper);

    @Update("UPDATE user SET password = #{newPwd} WHERE password = #{oldPwd} AND id=#{id}")
    int updatePwd(@Param("id") int id, @Param("oldPwd") String oldPwd,@Param("newPwd") String newPwd);

    @Update("UPDATE user SET password = #{newPwd} WHERE answer = #{answer} AND id=#{id}")
    int updatePwdByAnswer(@Param("id") int id, @Param("answer") String answer,@Param("newPwd") String newPwd);
}
